﻿using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;
using Sharp.Domain.Repositories;
using Sharp.Events;
using Sharp.Infrastructure.IoC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sharp.Domain.PlatformBoundedContext.UserModule.Events
{
    [Async]
    public class LoginedEventHandler : IEventHandler<LoginedEventData>
    {
        public LoginedEventHandler()
        {
        }
        public void Handle(LoginedEventData e)
        {
            var userRepository = ServiceLocator.Instance.GetService<IUserRepository>();
            var user = userRepository.Get(e.UserId);
            if (user != null)
            {
                user.LastLogonIp = e.LastLogonIp;
                user.LastLogonTime = DateTime.Now;

                userRepository.Context.Commit();
            }


        }
    }
}